package com.limao.Tool;

import java.io.IOException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class SMSWebchinese {
	private static String sin0="验证码：";
	private static String sin1="，尊敬的用户，您好，请在页面输入以完成验证。";
	private static String sin2="[买到家]";//"【桂林市“买到家”购物平台】";

	public static boolean send(String mobile,String code)
	{
		boolean success=false;
		String result =null;
		HttpClient client = new HttpClient();
		PostMethod post = new PostMethod("http://utf8.sms.webchinese.cn"); 
		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
		NameValuePair[] data ={ new NameValuePair("Uid", "feelworld01"),new NameValuePair("Key", "185f5e3cfbb9d1bd7c59"),new NameValuePair("smsMob",mobile),new NameValuePair("smsText",sin0+code+sin1+sin2)};
		post.setRequestBody(data);
		try {
			client.executeMethod(post);
			Header[] headers = post.getResponseHeaders();
			int statusCode = post.getStatusCode();
			System.out.println("statusCode:"+statusCode);
			for(Header h : headers)
			{
			System.out.println(h.toString());
			}
			result= new String(post.getResponseBodyAsString().getBytes("utf-8")); 
			System.out.println(result);
		} catch (IOException e) {
			result=null;
			e.printStackTrace();
		}
		post.releaseConnection();
		
		if(CacheClass.getIntValue(result)>0)
			success=true;
		
		return success;
	}

}
